﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using Newtonsoft.Json;

namespace Bbm.Persistence.Serializers
{
    public class GenericJsonSerializer : ISerializationStrategy
    {
    	readonly JsonSerializer serializer = JsonSerializer.Create(new JsonSerializerSettings());

    	public string Serialize<T>(T data)
        {
            var writer = new StringWriter();

            serializer.Serialize(writer, data);

            return writer.ToString();
        }

        public T Deserialize<T>(string serialized)
        {
        	return (T) serializer.Deserialize(new StringReader(serialized), typeof (T));
        }
    }
}
